package com.jrzh.mvc.convert.sys;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.jrzh.framework.base.convert.BaseConvertI;
import com.jrzh.bean.CheckResultBean;
import com.jrzh.common.exception.ProjectException;
import com.jrzh.mvc.model.sys.ManegeInfoModel;
import com.jrzh.mvc.view.sys.ManegeInfoView;
import com.jrzh.common.utils.ReflectUtils;

@Component("manegeInfoConvert")
public class ManegeInfoConvert implements BaseConvertI<ManegeInfoModel, ManegeInfoView> {

	@Override
	public ManegeInfoModel addConvert(ManegeInfoView view) throws ProjectException {
		ManegeInfoModel model = new ManegeInfoModel();
		ReflectUtils.copySameFieldToTarget(view, model);
		return model;
	}

	@Override
	public ManegeInfoModel editConvert(ManegeInfoView view, ManegeInfoModel model) throws ProjectException {
		ReflectUtils.copySameFieldToTargetFilter(view, model, new String[]{"createBy", "createTime"});
		return model;
	}

	@Override
	public ManegeInfoView convertToView(ManegeInfoModel model) throws ProjectException {
		ManegeInfoView view = new ManegeInfoView();
		ReflectUtils.copySameFieldToTarget(model, view);
		return view;
	}

	public ManegeInfoModel editSysInfo(ManegeInfoModel sysInfo, CheckResultBean info) {

		String status = info.getStatus();
		String sysCod = info.getSysCode();
		String endTime = info.getEndTime();
		String startTime = info.getStartTime();
		String chargeType = info.getChargeType();
		
		if(StringUtils.isNotBlank(status)) {
			sysInfo.setStatus(status);
		}
		if(StringUtils.isNotBlank(sysCod)) {
			sysInfo.setSysCode(sysCod);
		}
		if(StringUtils.isNotBlank(endTime)) {
			sysInfo.setEndTime(endTime);
		}
		if(StringUtils.isNotBlank(startTime)) {
			sysInfo.setStartTime(startTime);
		}
		if(StringUtils.isNotBlank(chargeType)) {
			sysInfo.setChargeType(chargeType);
		}
		
		return sysInfo;
	}

}
